package com.tadpole.music.view.activity.base;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import com.tadpole.music.R;
import com.tadpole.music.adapter.base.NineGridViewVpAdapter;
import com.tadpole.music.utils.NoDoubleClickListener;
import java.util.ArrayList;
import java.util.List;

/**
 * 大图展示
 * Created by SunYan
 * on 2020/4/17.
 */
public class LookBigPicActivity extends BaseActivity implements View.OnClickListener{
    private ViewPager viewPager;
    private TextView tvShowPicPosition;
    private List<String> mData = new ArrayList<>();
    private List<String> picTotalAddressOne;
    //大图下标
    private int picSubscript;
    private View viewBack;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fullScreen();
        setContentView(R.layout.activity_look_big_pic);
        picSubscript = getIntent().getIntExtra("pos",-1);
        picTotalAddressOne = (List<String>) getIntent().getSerializableExtra("uri");
        viewPager = (ViewPager) findViewById(R.id.vp);
        tvShowPicPosition= (TextView) findViewById(R.id.tv_show_pic_position);
        setVp();
        viewBack = findViewById(R.id.viewBack);
        viewBack.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                LookBigPicActivity.this.finish();
            }
        });
    }


    //全屏
    private void fullScreen() {
        if (Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        } else {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(option);
        }

    }

    private void setVp() {
        if(picTotalAddressOne!=null&&picTotalAddressOne.size()>0){
            for(int i=0;i<picTotalAddressOne.size();i++){
                mData.add(picTotalAddressOne.get(i));
            }
        }

        viewPager.setAdapter(new NineGridViewVpAdapter(this, mData, new NineGridViewVpAdapter.NineGridViewItemCLickListener() {
            @Override
            public void ItemClick() {
                finish();
            }

            @Override
            public void ItemLongClick(String itemPicAddress) {
            }
        },false,false));
        if(picSubscript!=-1){
            viewPager.setCurrentItem(picSubscript);
            picSubscript=picSubscript+1;
            tvShowPicPosition.setText(""+picSubscript+"/" + mData.size());
        }else {
            tvShowPicPosition.setText("1/" + mData.size());
        }
        viewPager.setOffscreenPageLimit(2);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
                tvShowPicPosition.setText((position+1)+"/"+mData.size());
            }
            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

    }


    @Override
    public void onClick(View v) {
    }
}
